package br.jonasLab.financistoweb.view.managed;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import br.jonasLab.financistoweb.control.ExtratosControl;
import br.jonasLab.financistoweb.vo.ExtratoAplicMesAnoVO;

@ManagedBean
@SessionScoped
public class RelatorioExtratoAplicacoesMB extends MB<ExtratoAplicMesAnoVO> {

	private Boolean rendTabela = new Boolean(false);
	private Integer periodoEmMeses;
	private Double totalDeposito;
	private Double totalJuros;
	private Double totalSaque;
	private Double taxaPeriodo;
	List<ExtratoAplicMesAnoVO> listVOs = new ArrayList<ExtratoAplicMesAnoVO>();
	
	public RelatorioExtratoAplicacoesMB(){
		super();
		setRendTabela(false);
	}
	
	@Override
	protected void initializeEntity() {
		
	}
	
	public String listar(){
		listVOs.clear();
		setPeriodoEmMeses(0);
		setTotalDeposito(0.0);
		setTotalJuros(0.0);
		setTotalSaque(0.0);
		setTaxaPeriodo(0.0000);
		ExtratosControl control = new ExtratosControl();
		try {
			List<ExtratoAplicMesAnoVO> listVOs = control.extratoAplicacoes();
			if(listVOs != null){
				setPeriodoEmMeses(listVOs.size());
				for (int i = 0; i < listVOs.size(); i++) {
					totalDeposito+= new BigDecimal(listVOs.get(i).getDeposito()).setScale(2,RoundingMode.HALF_EVEN).doubleValue();
					totalJuros+=new BigDecimal(listVOs.get(i).getJuros()).setScale(2,RoundingMode.HALF_EVEN).doubleValue();
					totalSaque+=new BigDecimal(listVOs.get(i).getSaque()).setScale(2,RoundingMode.HALF_EVEN).doubleValue();
					//calculara taxa
				}
				setListVOs(listVOs);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	
		setRendTabela(true);
		return null;
	}

	public List<ExtratoAplicMesAnoVO> getListVOs() {
		return listVOs;
	}

	public void setListVOs(List<ExtratoAplicMesAnoVO> listVOs) {
		this.listVOs = listVOs;
	}

	public Boolean getRendTabela() {
		return rendTabela;
	}

	public void setRendTabela(Boolean rendTabela) {
		this.rendTabela = rendTabela;
	}

	public Integer getPeriodoEmMeses() {
		return periodoEmMeses;
	}

	public void setPeriodoEmMeses(Integer periodoEmMeses) {
		this.periodoEmMeses = periodoEmMeses;
	}

	public Double getTotalDeposito() {
		return totalDeposito;
	}

	public void setTotalDeposito(Double totalDeposito) {
		this.totalDeposito = totalDeposito;
	}

	public Double getTotalJuros() {
		return totalJuros;
	}

	public void setTotalJuros(Double totalJuros) {
		this.totalJuros = totalJuros;
	}

	public Double getTotalSaque() {
		return totalSaque;
	}

	public void setTotalSaque(Double totalSaque) {
		this.totalSaque = totalSaque;
	}

	public Double getTaxaPeriodo() {
		return taxaPeriodo;
	}

	public void setTaxaPeriodo(Double taxaPeriodo) {
		this.taxaPeriodo = taxaPeriodo;
	}

}
